﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DockSample
{
    public partial class NFRTraceSelector : Form
    {
        HighOrderObjectDiagram diagram;
        //
        public NFRTraceSelector(HighOrderObjectDiagram diagram)
        {
            InitializeComponent();
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;

            this.diagram = diagram;
            initEntityTypeComBox();
        }
        //
        public string EntityType
        {
            get { return this.entityTypeComboBox.Text; }
        }
        public string EntityTarget
        {
            get { return this.entityTargetComboBox.Text; }
        }
        public string NFRName
        {
            get { return this.NFRNameComboBox.Text; }
        }
        //
        private void entityTypeComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            updataEntityTargetComboBox();
        }
        //
        private void entityTargetComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            updataNFRTypeComboBox();
        }
        //
        private void initEntityTypeComBox()
        {
            this.entityTypeComboBox.Items.Clear();
            this.entityTypeComboBox.Items.Add("Object");
            this.entityTypeComboBox.Items.Add("Attribute");
            this.entityTypeComboBox.Items.Add("Method");
            this.entityTypeComboBox.SelectedIndex = 0;
        }
        //
        private void updataEntityTargetComboBox()
        {
            this.entityTargetComboBox.Items.Clear();
            this.entityTargetComboBox.Text = "";

            if (this.entityTypeComboBox.Text.Equals("Object"))
            {
                this.entityTargetComboBox.Items.Add(this.diagram.Name);
                this.entityTargetComboBox.SelectedIndex = 0;
            }
            else if (this.entityTypeComboBox.Text.Equals("Attribute"))
            {
                if (this.diagram.AttributeList.Count != 0)
                {
                    foreach (Attribute attr in this.diagram.AttributeList)
                    {
                        this.entityTargetComboBox.Items.Add(attr.AttributeName);
                    }
                    this.entityTargetComboBox.SelectedIndex = 0;
                }
            }
            else if (this.entityTypeComboBox.Text.Equals("Method"))
            {
                if (this.diagram.MethodList.Count != 0)
                {
                    foreach (Method method in this.diagram.MethodList)
                    {
                        this.entityTargetComboBox.Items.Add(method.MethodName);
                    }
                    this.entityTargetComboBox.SelectedIndex = 0;
                }
            }
            else
            {
                MessageBox.Show("Internal Error ---entityTypeComboBox_SelectedValueChanged()");
            }
        }
        //
        private void updataNFRTypeComboBox()
        {
            this.NFRNameComboBox.Items.Clear();
            this.NFRNameComboBox.Text = "";

            if (this.entityTypeComboBox.Text.Equals("Object"))
            {
                if (this.diagram.ObjectNFRList.Count != 0)
                {
                    foreach (NonFunctionRequirment NFR in this.diagram.ObjectNFRList)
                    {
                        this.NFRNameComboBox.Items.Add(NFR.NonFunctionName);
                    }
                    this.NFRNameComboBox.SelectedIndex = 0;
                }
            }
            else if (this.entityTypeComboBox.Text.Equals("Attribute"))
            {
                foreach (Attribute tmpATTr in this.diagram.AttributeList)
                {
                    if (tmpATTr.AttributeName.Equals(this.entityTargetComboBox.Text))
                    {
                        if (tmpATTr.AttributeNFRList.Count != 0)
                        {
                            foreach (NonFunctionRequirment NFR in tmpATTr.AttributeNFRList)
                            {
                                this.NFRNameComboBox.Items.Add(NFR.NonFunctionName);
                            }
                            this.NFRNameComboBox.SelectedIndex = 0;
                        }
                        break;
                    }
                }
            }
            else if (this.entityTypeComboBox.Text.Equals("Method"))
            {
                foreach (Method tmpMethod in this.diagram.MethodList)
                {
                    if (tmpMethod.MethodName.Equals(this.entityTargetComboBox.Text))
                    {
                        if (tmpMethod.MethodNFRList.Count != 0)
                        {
                            foreach (NonFunctionRequirment NFR in tmpMethod.MethodNFRList)
                            {
                                this.NFRNameComboBox.Items.Add(NFR.NonFunctionName);
                            }
                            this.NFRNameComboBox.SelectedIndex = 0;
                        }
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("Internal Error ---entityTargetComboBox_SelectedValueChanged()");
            }
        } 
    }
}
